<template>
  <div class="container">
    <div class="common-header-wrap">
      <mt-header class="common-header" title="我的评价">
        <mt-button icon="back" slot="left" @click="$router.go(-1)"></mt-button>
      </mt-header>
    </div>
    <div
      class
      v-infinite-scroll="loadMore"
      infinite-scroll-disabled="loading"
      infinite-scroll-distance="10"
    >
      <div v-if="evaluateList && evaluateList.length">
        <div class="item mt-5" v-for="evaluate in evaluateList" :key="evaluate.ob_no">
          <div class="p-infoImf" @click="goDetail(evaluate.geval_goodsid)">
            <div class="p-img">
              <img :src="evaluate.geval_goodsimage" />
            </div>
            <div class="p-info">
              <div class="p-name">{{evaluate.geval_goodsname}}</div>
              <div class="p-score">
                <span class="common-score-wrapper">
                  <i class="iconfont front" :style="{width:evaluate.geval_scores/5*100+'%'}"></i>
                  <i class="iconfont back"></i>
                </span>
              </div>
              <div class="p-content">{{evaluate.geval_content}}</div>
            </div>
          </div>
          <div class="del-btn iconfont" @click="remove(evaluate)">&#xe6d8;</div>
        </div>
      </div>
      <div class="content">
        <div class="simulationAlert" v-if="isShow">
          <div class="title">提示</div>
          <div class="text">确定删除这条评论?删除后无法恢复</div>
          <div class="btn">
            <button class="btnLeft" @click="cancel">取消</button>
            <button class="btnRight" @click="clearallBrowse(comment)">确定</button>
          </div>
        </div>
        <div class="baffle" v-if="isShow"></div>
      </div>
      <empty-record v-if="evaluateList && !evaluateList.length"></empty-record>
    </div>
  </div>
</template>

<script>
import { Indicator } from "mint-ui";
import EmptyRecord from "../../../components/EmptyRecord";
import Popup from "../../Popup";
import {
  getMemberevaluateList,
  deleteMemberevaluateList,
} from "../../../api/memberEvaluate";
export default {
  name: "EvaluateList",
  components: {
    EmptyRecord,
    Popup,
  },
  data() {
    return {
      comment:"",
      isShow: false,
      params: { page: 0, per_page: 10 },
      loading: false, // 是否加载更多
      isMore: true, // 是否有更多
      evaluateList: false, // 商品列表
    };
  },
  methods: {
    cancel() {
      this.isShow = false;
    },
    clearallBrowse(item) {
      this.isShow = false;
      deleteMemberevaluateList(
        item.geval_id,
        item.geval_frommemberid,
        item.geval_storeid
      ).then((res) => {
        if (res.code == "10000") {
          this.getEvaluateList();
        }
      });
    },
    remove(item) {
      this.isShow = true;
      this.comment = item;

      // deleteMemberevaluateList(
      //   item.geval_id,
      //   item.geval_frommemberid,
      //   item.geval_storeid
      // ).then((res) => {
      //   if (res.code == "10000") {
      //     this.getEvaluateList();
      //   }
      // });
      //   geval_id   geval_storeid geval_frommemberid
    },
    goDetail(goods_id) {
      this.$router.push({
        name: "HomeGoodsdetail",
        query: { goods_id: goods_id },
      });
    },
    getEvaluateList(ispush) {
      Indicator.open();
      let params = this.params;
      getMemberevaluateList(params).then((res) => {
        Indicator.close();

        if (ispush && this.evaluateList) {
          this.evaluateList = this.evaluateList.concat(
            res.result.goodsevallist
          );
        } else {
          this.evaluateList = res.result.goodsevallist;
        }
        if (res.result.hasmore) {
          this.isMore = true;
        } else {
          this.isMore = false;
        }
      });
    },
    loadMore() {
      this.loading = true;
      this.params.page = ++this.params.page;
      if (this.isMore) {
        this.loading = false;
        this.getEvaluateList(true);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.item {
  display: flex;
  display: -webkit-flex;
  justify-content: space-between;
  background: #fff;
  padding: 0.5rem;
}
.p-infoImf {
  display: flex;
}
.item .p-img {
}
.item .p-img img {
  width: 3rem;
  height: 3rem;
}
.item .p-info {
  margin-left: 0.2rem;
}
.item .p-info .p-name {
  line-height: 1rem;
  font-size: 0.6rem;
}
.item .p-info .p-score {
}
.item .p-info .p-content {
  font-size: 0.5rem;
  line-height: 0.8rem;
}

.simulationAlert {
  position: fixed;
  top: 35vh;
  left: 5vw;
  z-index: 1100;
  width: 90vw;
  height: 160px;
  text-align: center;
  font-size: 0;
  background: #ffffff;

  .title {
    margin-top: 15px;
    font-size: 20px;
    color: #333;
  }
  .text {
    margin-top: 20px;
    font-size: 18px;
    color: #999;
  }
  .btn {
    position: absolute;
    left: 0;
    bottom: 0;
    z-index: 1200;
    width: 100%;
    height: 40px;
    border-top: 1px solid #ddd;
  }
  .btn button {
    width: 50%;
    height: 40px;
    line-height: 40px;
    box-sizing: border-box;
    font-size: 16px;
    border: none;
    background-color: #ffffff;
  }
  .btnLeft {
    border-right: 1px solid #ddd !important;
  }
  .btnRight {
    color: #e93b3d;
  }
}
.baffle {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1003;
  width: 100vw;
  height: 100vh;
  background: #000;
  opacity: 0.5;
}
</style>
